/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sunsite.action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.support.ResourceBundleMessageSource;
import sunsite.po.ResourceCatelog;
import sunsite.po.ResourceType;
import sunsite.po.Usr;
import sunsite.service.FileService;
import sunsite.tools.Helper;
import sunsite.tools.Pagination;

/**
 *
 * @author cyp
 */
public class FileManage extends ActionSupport {
    public static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Register.class);

    private List<sunsite.po.ResourceTp> Resource_tpList;
    private List<sunsite.po.ResourceCatelog> Resource_catelogList;
    private List<sunsite.po.ResourceType> Resource_typeList;
    
    private String type;
    private String rtp;
    private String rcatelog;
    private String rtype;
    private String rtypeitem;

    private List<sunsite.po.Resource> ResourceList;
    private String resId;
    private String resName;
    private String address;
    private int status;
    private Date uploadTime;
    private Date lastUpdate;
    private String discription;
    private Usr usr;

    private Pagination pagination;//分页类
    private String url;

    private ResourceBundleMessageSource messageSource;
    private FileService fileService;
    @Override
    public String execute() throws Exception {
        if (type != null && type.equals("getForm")) {//初始化
            Resource_tpList = fileService.getAllResourceTp();
            Resource_catelogList = new ArrayList();//初始化
            Resource_typeList = new ArrayList();//初始化
            // <editor-fold  defaultstate="collapsed" desc="分页初始化">
            //int size = 10;//每页记录条数
            if (pagination == null) {
                pagination = new Pagination();//new Pagination(size)默认为size为10
            }
            //pagination.setSize(size);
            ResourceList = fileService.getResourceList(pagination);
            url = "fileManage.action";
            // </editor-fold>            
            return INPUT;
        }
        if (type != null && type.equals("rtp")) {//下拉列表可访问类别
            int i = Integer.parseInt(rtp);
            if (i != 0) {
                Resource_catelogList = fileService.getResourceCatelogList(i);
                Resource_typeList = new ArrayList();//清空下拉表
            }
            return SUCCESS;
        }
        if (type != null && type.equals("rcatelog")) {//下拉列表资源归类
            int i = Integer.parseInt(rcatelog);
            if (i != 0) {
                Resource_typeList = fileService.getResourceTypeList(i);
            }
            return SUCCESS;
        }
        if (type != null && type.equals("rtype")) {//下拉列表资源类型
            Map<String,Object> map=new HashMap();
            map.put("rtp", Helper.setPara(rtp));
            map.put("rcatelog", Helper.setPara(rcatelog));
            map.put("rtype", Helper.setPara(rtype));//查询参数
            ResourceList = fileService.getResourceList(pagination,map);
            return SUCCESS;
        }
        if (type != null && type.equals("rtypeitem")) {//增加资源类型项
            Integer catId=Integer.parseInt(rcatelog);
            if( catId != 0){
            ResourceType resourceType = new ResourceType();
            ResourceCatelog resourceCatelog = fileService.getResourceCatelog(catId);
            resourceType.setResourceCatelog(resourceCatelog);
            resourceType.setTypeName(rtypeitem);
            fileService.addResourceType(resourceType);
            Resource_typeList = fileService.getResourceTypeList(catId);
            }
            return SUCCESS;
        }
        if (type != null && type.equals("select")) {//选择页码
            if (pagination.getCurrentPage() <= 0) {
                pagination.setCurrentPage(1);
            }
            if (pagination.getTotalPage() != 0 && pagination.getCurrentPage() > pagination.getTotalPage()) {
                pagination.setCurrentPage(pagination.getTotalPage());
            }
            ResourceList = fileService.getResourceList(pagination);
            if (this.ResourceList.size() == 0 && pagination.getCurrentPage() != 1) {
                pagination.setCurrentPage(pagination.getCurrentPage() - 1);
                ResourceList = fileService.getResourceList(pagination);
            }
            return INPUT;
        }
        if (type != null && type.equals("find")) {//查找
            Map<String,Object> map=new HashMap();            
            map.put("rtp", Helper.setPara(rtp));
            map.put("rcatelog", Helper.setPara(rcatelog));
            map.put("rtype", Helper.setPara(rtype));
            ResourceList = fileService.getResourceList(pagination,map);
            return INPUT;
        }
        if (type != null && type.equals("modify")) {//修改记录
            return "modify";
        }
        if (type != null && type.equals("delete")) {//删除记录
            if (resId != null && !resId.equals("")) {
                fileService.deleteResource(resId);
            }
            if (pagination == null) {
                pagination = new Pagination();
            }
            ResourceList = fileService.getResourceList(pagination);
            return INPUT;
        }
        return SUCCESS;
    }

    /**
     * @return the Resource_tpList
     */
    public List<sunsite.po.ResourceTp> getResource_tpList() {
        return Resource_tpList;
    }

    /**
     * @param Resource_tpList the Resource_tpList to set
     */
    public void setResource_tpList(List<sunsite.po.ResourceTp> Resource_tpList) {
        this.Resource_tpList = Resource_tpList;
    }

    /**
     * @return the Resource_catelogList
     */
    public List<sunsite.po.ResourceCatelog> getResource_catelogList() {
        return Resource_catelogList;
    }

    /**
     * @param Resource_catelogList the Resource_catelogList to set
     */
    public void setResource_catelogList(List<sunsite.po.ResourceCatelog> Resource_catelogList) {
        this.Resource_catelogList = Resource_catelogList;
    }

    /**
     * @return the Resource_typeList
     */
    public List<sunsite.po.ResourceType> getResource_typeList() {
        return Resource_typeList;
    }

    /**
     * @param Resource_typeList the Resource_typeList to set
     */
    public void setResource_typeList(List<sunsite.po.ResourceType> Resource_typeList) {
        this.Resource_typeList = Resource_typeList;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the rtp
     */
    public String getRtp() {
        return rtp;
    }

    /**
     * @param rtp the rtp to set
     */
    public void setRtp(String rtp) {
        this.rtp = rtp;
    }

    /**
     * @return the rcatelog
     */
    public String getRcatelog() {
        return rcatelog;
    }

    /**
     * @param rcatelog the rcatelog to set
     */
    public void setRcatelog(String rcatelog) {
        this.rcatelog = rcatelog;
    }

    /**
     * @return the rtype
     */
    public String getRtype() {
        return rtype;
    }

    /**
     * @param rtype the rtype to set
     */
    public void setRtype(String rtype) {
        this.rtype = rtype;
    }

    /**
     * @return the ResourceList
     */
    public List<sunsite.po.Resource> getResourceList() {
        return ResourceList;
    }

    /**
     * @param ResourceList the ResourceList to set
     */
    public void setResourceList(List<sunsite.po.Resource> ResourceList) {
        this.ResourceList = ResourceList;
    }

    /**
     * @return the resId
     */
    public String getResId() {
        return resId;
    }

    /**
     * @param resId the resId to set
     */
    public void setResId(String resId) {
        this.resId = resId;
    }

    /**
     * @return the resName
     */
    public String getResName() {
        return resName;
    }

    /**
     * @param resName the resName to set
     */
    public void setResName(String resName) {
        this.resName = resName;
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @return the status
     */
    public int getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(int status) {
        this.status = status;
    }

    /**
     * @return the uploadTime
     */
    public Date getUploadTime() {
        return uploadTime;
    }

    /**
     * @param uploadTime the uploadTime to set
     */
    public void setUploadTime(Date uploadTime) {
        this.uploadTime = uploadTime;
    }

    /**
     * @return the lastUpdate
     */
    public Date getLastUpdate() {
        return lastUpdate;
    }

    /**
     * @param lastUpdate the lastUpdate to set
     */
    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    /**
     * @return the discription
     */
    public String getDiscription() {
        return discription;
    }

    /**
     * @param discription the discription to set
     */
    public void setDiscription(String discription) {
        this.discription = discription;
    }

    /**
     * @return the usr
     */
    public Usr getUsr() {
        return usr;
    }

    /**
     * @param usr the usr to set
     */
    public void setUsr(Usr usr) {
        this.usr = usr;
    }

    /**
     * @return the pagination
     */
    public Pagination getPagination() {
        return pagination;
    }

    /**
     * @param pagination the pagination to set
     */
    public void setPagination(Pagination pagination) {
        this.pagination = pagination;
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * @return the messageSource
     */
    public ResourceBundleMessageSource getMessageSource() {
        return messageSource;
    }

    /**
     * @param messageSource the messageSource to set
     */
    public void setMessageSource(ResourceBundleMessageSource messageSource) {
        this.messageSource = messageSource;
    }

    /**
     * @return the fileService
     */
    public FileService getFileService() {
        return fileService;
    }

    /**
     * @param fileService the fileService to set
     */
    public void setFileService(FileService fileService) {
        this.fileService = fileService;
    }

    /**
     * @return the rtypeitem
     */
    public String getRtypeitem() {
        return rtypeitem;
    }

    /**
     * @param rtypeitem the rtypeitem to set
     */
    public void setRtypeitem(String rtypeitem) {
        this.rtypeitem = rtypeitem;
    }
}


